<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-shopping-bag-2"></i> 信息列表 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-date-picker class="mr10" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
                        v-model="query.time">
        </el-date-picker>
        <el-select class="mr10" v-model="query.sel" placeholder="请选择可见/隐藏数据">
          <el-option label="全部可见/隐藏数据" value=""></el-option>
          <el-option label="全部可见数据" value="1"></el-option>
          <el-option label="全部隐藏数据" value="0"></el-option>
        </el-select>
        <el-select class="mr10" v-model="query.ex" placeholder="请选择待审核事件">
          <el-option label="全部数据" value=""></el-option>
          <el-option label="全部待审核数据" value="1"></el-option>
          <el-option label="全部审核完成数据" value="2"></el-option>
        </el-select>
        <el-input placeholder="请输入名字查询" v-model="query.souVal" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="souClick">搜索</el-button>
      </div>
      <el-table v-loading="loading" :data="tableData" border class="table" style="width: 100%" ref="multipleTable"
                header-cell-class-name="table-header" @selection-change="SelectionChange">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="sbSname" label="人员姓名" width="180">
          <template slot-scope="scope">
            <el-link type="primary" :underline="false" @click="detailedClick(scope.row)">{{scope.row.sbSname}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="sbSphone" label="电话" width="150"></el-table-column>
        <el-table-column prop="idCard" label="身份证号" width="200"></el-table-column>
        <el-table-column prop="sbCreateTime" label="创建时间" width="210"></el-table-column>
        <el-table-column prop="sbUpdateTime" label="更新时间" width="210"></el-table-column>
        <el-table-column prop="mobileCreate" fixed="right" label="是否可见" width="160">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.sbIsOpen" active-text="显示" active-value="1" inactive-text="隐藏" inactive-value="0"
                       @change="switchChange(scope.row)">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="150" align="center">
          <template slot-scope="scope">
            <div style="padding-top:10px;">
              <el-badge :value="scope.row.onAuditNum" class="item">
                <el-button type="text" icon="el-icon-view" class="red" @click="waitClick(scope.row)">待审核事件</el-button>
              </el-badge>
            </div>
            <el-button type="text" icon="el-icon-delete-solid
" class="red" @click="delClick(scope.row)" :loading="scope.row.delLoad">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.page" :page-size="query.limit" :total="page.totalCount"
                       :pager-count="5" @current-change="PageChange" @prev-click="PageChange" @next-click="PageChange"></el-pagination>
      </div>
      <!-- 查看详情 -->
      <el-dialog title="详细信息" :visible.sync="detailedFlg" width="40%">
        <div v-loading="detailedLoad">
          <el-row class="nameDialogHead">
            <el-col :span="24" class="headcol">
              {{detailedObj.staff.sbSname}}
              <span>{{detailedObj.staff.sbSex}}</span>
            </el-col>
            <el-col :span="8" class="headcol">
              <i class="el-icon-phone"></i>
              <span>{{detailedObj.staff.sbSphone}}</span>
            </el-col>
            <el-col :span="8" class="headcol">
              <i class="el-icon-user-solid"></i>
              <span>{{detailedObj.staff.idCard}}</span>
            </el-col>
          </el-row>
          <el-collapse accordion @change="companyClick">
            <el-collapse-item v-for="item in detailedObj.comList" :title="item.name" :name="item.baseId">
              <template slot="title">
                <div style="line-height:20px;flex:1">
                  <span style="margin-right:10px;">{{item.name}}</span>
                  <p>{{item.address}}</p>
                </div>
                <el-button type="danger" size="mini" round>{{item.num}}</el-button>
              </template>
              <div style="padding:0 10px;">
                <el-collapse accordion class="GSList">
                  <el-collapse-item v-for="(e,i) in detailedList" name="1">
                    <template slot="title">
                      <el-tag>{{e.siTag}}</el-tag>
                      <span style="margin-left:10px;flex:1;">事件{{i + 1}}</span>
                      <el-tag :type="e.siStatus == 2 ? 'danger' : ''">{{e.siStatus == 2 ? '审核不通过' : '审核通过'}}</el-tag>
                    </template>
                    <el-row>
                      <el-col :span="12">
                        <p>工作职责</p>
                        <p>{{e.siJob}}</p>
                      </el-col>
                      <el-col :span="12">
                        <p>性质</p>
                        <p>
                          <el-tag>{{e.siTag}}</el-tag>
                        </p>
                      </el-col>
                      <el-col :span="24">
                        <p>事件说明</p>
                        <p>{{e.siRemarks}}</p>
                      </el-col>
                      <el-col :span="24">
                        <p>说明图片</p>
                        <p>
                          <el-image v-for="ev in e.siPic" style="width: 80px; height: 80px;margin:0 10px 10px 0;" :src="ev" fit="fill"
                                    :preview-src-list="[ev]"></el-image>
                        </p>
                      </el-col>
                      <el-col :span="24">
                        <p>说明视频</p>
                        <p>
                        <div v-for="ev in e.siVideo" style="width:80px;height:80px;margin:0 10px 10px 0;text-align:center;background:#eee;"
                             @click="videoClick(ev)">
                          <i class="el-icon-video-play" style="line-height:80px;font-size:30px;color:#666;"></i>
                        </div>
                        </p>
                      </el-col>
                    </el-row>
                  </el-collapse-item>
                </el-collapse>
              </div>
            </el-collapse-item>
          </el-collapse>
        </div>

      </el-dialog>
      <!-- 审核操作 -->
      <el-dialog title="事件审核" :visible.sync="exFlg" width="40%">
        <el-collapse accordion class="GSList" v-loading="exLoad">
          <el-collapse-item v-for="item in exList" :name="item.siId">
            <template slot="title">
              <el-tag>{{item.siTag}}</el-tag>
              <span style="margin-left:10px;flex:1">{{item.companyName}}</span>
              <el-tag>待审核</el-tag>
            </template>
            <el-row>
              <el-col :span="12">
                <p>工作职责</p>
                <p>{{item.siJob}}</p>
              </el-col>
              <el-col :span="12">
                <p>性质</p>
                <p>
                  <el-tag>{{item.siTag}}</el-tag>
                </p>
              </el-col>
              <el-col :span="24">
                <p>事件说明</p>
                <p>{{item.siRemarks}}</p>
              </el-col>
              <el-col :span="24">
                <p>说明图片</p>
                <p>
                  <el-image v-for="e in item.siPic" style="width: 80px; height: 80px;margin:0 10px 10px 0;" :src="e" fit="fill"
                            :preview-src-list="[e]"></el-image>
                </p>
              </el-col>
              <el-col :span="24">
                <p>说明视频</p>
                <p>
                <div v-for="e in item.siVideo" style="width:80px;height:80px;margin:0 10px 10px 0;text-align:center;background:#eee;"
                     @click="videoClick(e)">
                  <i class="el-icon-video-play" style="line-height:80px;font-size:30px;color:#666;"></i>
                </div>
                </p>
              </el-col>
              <el-col :span="24" style="text-align:right;">
                <el-button type="primary" icon="el-icon-view" @click="exYesClick(item)" :loading="item.btnLoad">审核通过</el-button>
                <el-button type="danger" icon="el-icon-view" @click="exNoClick(item)" :loading="item.btnLoad">审核不通过</el-button>
              </el-col>
            </el-row>
          </el-collapse-item>
        </el-collapse>
      </el-dialog>
      <!-- 审核不通过原因 -->
      <el-dialog title="审核不通过原因" :visible.sync="exNoFlg" width="40%">
        <el-input type="textarea" :rows="5" placeholder="请说明原因" v-model="exNoText">
        </el-input>
        <span slot="footer" class="dialog-footer">
          <el-button @click="exNoFlg = false">取 消</el-button>
          <el-button type="primary" @click="exNoTextClick" :loading="exNoLoad">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 查看视频 -->
      <el-dialog title="查看视频" :visible.sync="videoFlg" width="40%" @close="videoOff">
        <div v-html="videoHtml"></div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { jdDataListInit, jdDataListwait, jdDataListwaitEvent, jdDataListIsopen, jdDataListDel, jdDataListXQ, jdDataListXQEven } from '../../../api/index';

export default {
  data() {
    return {
      loading: false,
      query: {
        page: 1,
        limit: 10,
        time: [],
        souVal: '',
        sel: '',
        ex: ''
      },
      tableData: [],
      page: {
        totalCount: 100
      },
      //查看详情
      detailedFlg: false,
      detailedLoad: false,
      detailedObj: {
        staff: {},
        comList: []
      },
      detailedList: [],
      //事件审核
      exFlg: false,
      exLoad: false,
      exId: '',
      exList: [],
      //审核不通过原因
      exNoFlg: false,
      exNoId: '',
      exNoLoad: false,
      exNoText: '',
      // 查看视频
      videoFlg: false,
      videoHtml: '',
    };
  },
  created() {
    this.getListData();
  },
  methods: {
    //列表信息
    getListData() {
      this.loading = true;
      let query = {
        startTime: this.query.time ? this.query.time[0] : '',
        endTime: this.query.time ? this.query.time[1] : '',
        kw: this.query.souVal,
        limit: this.query.limit,
        page: this.query.page,
        isOpen: this.query.sel,
        status: this.query.ex
      };
      jdDataListInit(query).then((res) => {
        this.loading = false;
        if (res.code === 0) {
          res.recordList.map(item => {
            item.sbIsOpen = String(item.sbIsOpen);
            item['delLoad'] = false;
          })
          this.tableData = res.recordList;
          this.page.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      });
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //翻页
    PageChange(num) {
      this.query.page = num;
      this.getListData();
    },
    //搜索
    souClick() {
      this.query.page = 1;
      this.getListData();
    },
    //选中
    SelectionChange() { },
    //点击详情
    detailedClick(item) {
      this.detailedFlg = true;
      this.detailedLoad = true;
      jdDataListXQ({
        baseId: item.sbId
      }).then(res => {
        this.detailedLoad = false;
        if (res.code == 0) {
          this.detailedObj = res;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //查看公司下的事件
    companyClick(val) {
      this.detailedList = [];
      jdDataListXQEven({
        baseId: val
      }).then(res => {
        if (res.code == 0) {
          res.infoList.map(item => {
            if (item.siPic.indexOf(",") > -1) {
              item.siPic = item.siPic.split(",");
            } else {
              item.siPic = [item.siPic];
            }
            if (item.siVideo.indexOf(",") > -1) {
              item.siVideo = item.siVideo.split(",");
            } else {
              item.siVideo = [item.siVideo];
            }
          })
          this.detailedList = res.infoList;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //待审核事件
    waitClick(item) {
      this.exId = item;
      if (item.onAuditNum > 0) {
        this.exFlg = true;
        this.exLoad = true;
        jdDataListwait({
          baseId: item.sbId
        }).then(res => {
          this.exLoad = false;
          if (res.code == 0) {
            if (res.infoList.length == 0) {
              this.exFlg = false;
              this.getListData();
              return false;
            }
            res.infoList.forEach(item => {
              if (item.siPic.indexOf(",") > -1) {
                item.siPic = item.siPic.split(",");
              } else {
                item.siPic = [item.siPic];
              }
              if (item.siVideo.indexOf(",") > -1) {
                item.siVideo = item.siVideo.split(",");
              } else {
                item.siVideo = [item.siVideo];
              }
              item['btnLoad'] = false;
            })
            this.exList = res.infoList;
          } else {
            this.$message(res.msg);
          }
        })
      } else {
        this.$message('暂无事件处理');
      }
    },
    //审核通过
    exYesClick(item) {
      item.btnLoad = true;
      jdDataListwaitEvent({
        infoId: item.siId,
        status: 1,
        failReason: '',
      }).then(res => {
        item.btnLoad = false;
        if (res.code == 0) {
          this.$message.success('操作成功');
          this.waitClick(this.exId);
        } else {
          this.$message(res.msg);
        }
      })
    },
    //审核不通过
    exNoClick(item) {
      this.exNoFlg = true;
      this.exNoId = item.siId;
    },
    //审核不通过提交
    exNoTextClick(item) {
      if (this.exNoText) {
        this.exNoLoad = true;
        jdDataListwaitEvent({
          infoId: this.exNoId,
          status: 2,
          failReason: this.exNoText,
        }).then(res => {
          this.exNoLoad = false;
          if (res.code == 0) {
            this.exNoFlg = false;
            this.$message.success('操作成功');
            this.waitClick(this.exId);
          } else {
            this.$message(res.msg);
          }
        })
      }
    },
    //点击查看视频
    videoClick(src) {
      this.videoFlg = true;
      this.videoHtml = `<video src="${src}" controls style="width:100%;height:300px;"></video>`
    },
    //关闭查看视频
    videoOff() {
      this.videoHtml = '';
    },
    //可见不可见
    switchChange(item) {
      jdDataListIsopen({
        baseId: item.sbId,
        isOpen: item.sbIsOpen
      }).then(res => {
        if (res.code == 0) {
          this.$message.success('操作成功');
          this.getListData();
        } else {
          this.$message(res.msg);
        }
      })
    },
    //删除
    delClick(item) {
      this.$confirm("确定删除此条信息吗？", "提示", {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消操作',
        type: 'warning',
      }).then(() => {
        item.delLoad = true;
        jdDataListDel({
          baseId: item.sbId
        }).then(res => {
          item.delLoad = false;
          if (res.code == 0) {
            this.$message.success('操作成功');
            this.getListData();
          } else {
            this.$message(res.msg);
          }
        })
      })
    },
  }
};
</script>

<style scoped>
/deep/ :focus {
    outline: 0;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.nameDrawer {
    padding: 30px;
}
.elSelect {
    width: 100%;
}
.upload-demo {
    height: 32px;
}
.heng-border {
    height: 0.5px;
    margin-bottom: 30px;
}

/* 截图 */
.cropper-content .cropper {
    width: auto;
    height: 300px;
}
.refund-list {
    margin-bottom: 10px;
}
.payment_type {
    padding: 10px 0;
}
</style>
<style>
.nameDialogHead .headcol:nth-child(1) {
    font-size: 26px;
    font-weight: bold;
    margin-bottom: 20px;
}
.nameDialogHead .headcol:nth-child(1) span {
    font-size: 16px;
    margin-left: 20px;
}
.nameDialogHead .headcol:nth-child(2),
.nameDialogHead .headcol:nth-child(3) {
    font-size: 15px;
    color: #409eff;
    margin-bottom: 20px;
}
.GSList .el-col p:nth-child(1) {
    color: #999;
    margin-top: 10px;
}
.GSList .el-col .el-image {
    margin-right: 10px;
}
</style>
